<script setup lang="ts">
  import { useI18n } from '/@/hooks/web/useI18n';
  // import { useMessage } from '/@/hooks/web/useMessage';
  import { unref } from 'vue';
  import { router } from '/@/router';
  import { FormProps } from '/@/components/Form';
  import { BasicTable, useTable } from '/@/components/Table';
  import { carddZcmxIndexListData } from '/@/api/cardd/zcmx/carddZcmx';
  import { useGo } from '/@/hooks/web/usePage';

  const { t } = useI18n('cardd.zcmx.carddZcmx');
  // const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const go = useGo();

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('租车明细表管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('用车单位'),
        field: 'zcmxYcdw',
        component: 'Input',
      },
      // {
      //   label: t('车单编号'),
      //   field: 'zcmxCdbh',
      //   component: 'Input',
      // },
      {
        label: t('上车时间'),
        field: 'zcmxScsj',
        component: 'Input',
      },
      {
        label: t('下车时间'),
        field: 'zcmxXcsj',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('用车单位'),
      dataIndex: 'zcmxYcdw',
      key: 'a.zcmx_ycdw',
      sorter: true,
      width: 230,
      align: 'left',
    },
    {
      title: t('月份'),
      dataIndex: 'zcmxYf',
      key: 'a.zcmx_yf',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('服务时长'),
      dataIndex: 'zcmxFwsz',
      key: 'a.zcmx_fwsz',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('实际里程'),
      dataIndex: 'zcmxSjlc',
      key: 'a.zcmx_sjlc',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('租车费'),
      dataIndex: 'zcmxZcf',
      key: 'a.zcmx_zcf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('超里程数'),
      dataIndex: 'zcmxClcs',
      key: 'a.zcmx_clcs',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('超里程费'),
      dataIndex: 'zcmxClcf',
      key: 'a.zcmx_clcf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('超时时长'),
      dataIndex: 'zcmxCssz',
      key: 'a.zcmx_cssz',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('超时费'),
      dataIndex: 'zcmxCsf',
      key: 'a.zcmx_csf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('过路费'),
      dataIndex: 'zcmxGlf',
      key: 'a.zcmx_glf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('洗车费'),
      dataIndex: 'zcmxXcf',
      key: 'a.zcmx_xcf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('停车费'),
      dataIndex: 'zcmxTcf',
      key: 'a.zcmx_tcf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('餐费'),
      dataIndex: 'zcmxCf',
      key: 'a.zcmx_cf',
      sorter: true,
      width: 130,
      align: 'right',
    },
    {
      title: t('住宿费'),
      dataIndex: 'zcmxSf',
      key: 'a.zcmx_sf',
      sorter: true,
      width: 130,
      align: 'right',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 80,
    actions: (record: Recordable) => [
      {
        icon: 'i-simple-line-icons:chart',
        title: t('查看租车明细表'),
        onClick: handleDetail.bind(this, record),
        auth: 'cardd:zcmx:carddZcmx:view',
      },
    ],
  };

  const [registerTable] = useTable({
    api: carddZcmxIndexListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleDetail(record: Recordable) {
    go({
      path: '/cardd/zcmx/carddZcmx/list',
      query: { zcmxYcdw: record.zcmxYcdw, zcmxYf: record.zcmxYf },
    });
  }
</script>

<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
    </BasicTable>
  </div>
</template>

<style scoped lang="less"></style>
